#!/bin/bash 
# 2008-12-16 pb send file xxxxx.log to vlbeer 
# Renames logfile with station code and ftp's it. 
# Renames ftp version back to local 
# Doesn't need '.log' extension. 
# Procedure call sy =exec lgput `lognm`.log cm
#
# 2013-12-13 - lgput_ra generated from lgput.
# 2013-12-16 - Added extra variable to hold the name for the long experiment name.
# The experiments have short and long form names which differ by a couple of
# characters. Typically long -> short is raks -> rk

LONGNAME=raks

echo "Send VLBI RA Logfile v1.0.."



 if [ $# -lt 2 ];
   then
    echo "Syntax: $(basename $0) <filename> <stn>"
    exit 1
 fi
 
 if [ "$2" != jb ] && [ "$2" != cm ] && [ "$2" != kn ] && [ "$2" != da ] \
     && [ "$2" != de ] && [ "$2" != ta ]
     then
      echo "Unknown Station"
      exit 4
     fi
     
cd /usr2/log            
FILE=`echo $1 |cut -f1 -d '.'`
if [ ! -f "$FILE".log ]
 then 
  echo "$FILE.log file not found"
  exit 2
fi
     
OUTF=$FILE$2
mv $FILE.log $OUTF.log

LONG=$LONGNAME${FILE:2}
echo $LONG

MONTH=$(date +"%m")
YEAR=$(date +"%Y")
DAY=$(date +"%d")
#DAY=20
VDIR="GRT_log_files/${YEAR}_${MONTH}/${YEAR}_${MONTH}_${DAY}_${LONG}/"
echo "Dir: $VDIR "
  
echo "Sending VLBI RA Logfile (v1.0)..$FILE $OUTF" 
ncftpput -u grt -p "<PWDHERE>" webinet.asc.rssi.ru $VDIR $OUTF.log 2>&1
echo "sendlog result code $?"
result="sendlog result code $?, $OUTF"
inject_snap "\"$result\""
mv $OUTF.log $FILE.log
cd

### EOF ###
